#include "mytz.h"

mytz::mytz(QString btnimg){
    QPixmap pix;
    bool ret=pix.load(btnimg);
    if(!ret){
        QString str=QString("图片加载失败").arg(btnimg);
        qDebug()<<str;
        return;
    }
    this->setFixedSize(pix.width(),pix.height());
    this->setStyleSheet("QPushButton{border:0px;}");
    this->setIcon(pix);
    this->setIconSize(QSize(pix.width(),pix.height()));
    //初始化计时器
    timer1=new QTimer(this);
    timer2=new QTimer(this);
    connect(timer1,&QTimer::timeout,[=](){
        QPixmap pix;
        QString str=QString(":/jtz%1.jpg").arg(this->min++);
        pix.load(str);
        this->setFixedSize(pix.width(),pix.height());
        this->setStyleSheet("QPushButton{border:0px;}");
        this->setIcon(pix);
        this->setIconSize(QSize(pix.width(),pix.height()));
        if(this->min>this->max){
            this->min=1;
            timer1->stop();
        }
    });
     connect(timer2,&QTimer::timeout,[=](){
            QPixmap pix;
            QString str=QString(":/jtz%1.jpg").arg(this->max--);
            pix.load(str);
            this->setFixedSize(pix.width(),pix.height());
            this->setStyleSheet("QPushButton{border:0px;}");
            this->setIcon(pix);
            this->setIconSize(QSize(pix.width(),pix.height()));
            if(this->max<this->min){
                this->max=2;
                timer2->stop();
            }

    });

}
void mytz::mousePressEvent(QMouseEvent*e){
    if(this->iswin){
        return;
    }
    else{
        QPushButton::mousePressEvent(e);
    }
}
void mytz::changeflag(){
    if(this->flag){
        timer1->start(30);
        this->flag=false;
    }
     else{
            timer2->start(30);
            this->flag=true;
    }

}
